import React, {Component} from "react";
import {Dimensions, StyleSheet, View} from 'react-native';

let viewRoot: any = null;

/**
 *  ReactNative实现Toast: https://www.jianshu.com/p/1b1ec73b2243
 *
 * */


const {width, height} = Dimensions.get("window");
type RootViewState = {
    view: any
}

export default class ToastRootView extends Component<any, RootViewState> {
    constructor(props) {
        super(props);
        viewRoot = this;
        this.state = {
            view: null,
        }
    }

    render() {
        return (
            <View style={styles.rootView} pointerEvents="box-none">
              {this.state.view}
           </View>
        )
    }

    public static setView = (view) => {
        if(viewRoot){
            viewRoot.setState({view: view})
        }
        if(view){
            console.log(` Toast check width:${width}, height: ${height}`);
        }
    };
}

const styles = StyleSheet.create({
    rootView: {
        position: "absolute",
        left: 0,
        right: 0,
        top: height * 4 / 5,
        // bottom: 0,
        flexDirection: "row",
        justifyContent: "center",
    }
});

